package util;

import action.userAction;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import model.Guashi;
import service.IUserService;

import java.util.List;
import java.util.Map;

public class guashiInter extends AbstractInterceptor {

    private IUserService userService;

    public IUserService getUserService() {
        return userService;
    }

    public void setUserService(IUserService userService) {
        this.userService = userService;
    }

    public String intercept(ActionInvocation arg0) throws Exception {
        userAction userAction = (action.userAction) arg0.getAction();
        String username = userAction.getUser().getUsername();
        List list = userService.getGuashi();
        for (Object aList : list) {
            if (((Guashi) aList).getUser().getUsername().equals(username)) {
                System.out.println(((Guashi) aList).getUser().getUsername());
                Map request = (Map) arg0.getInvocationContext().get("request");
                request.put("msg", "挂失失败");
                System.out.println("sorry");
                return Action.ERROR;
            }
        }
        return arg0.invoke();
    }

}
